﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3_OverloadingAndParsing
{
    class Asset
    {
        public string Name;
    }
    class Stock : Asset
    {
        public long SharesOwned; //拥有的股份
    }
    class House : Asset
    {
        public decimal Mortgage; //抵押贷款
    }
    class Chapt3_2_9OverloadingAndParsing
    {
        static void Foo(Asset a) { Console.WriteLine("Asset Foo()."); }
        static void Foo(House a) { Console.WriteLine("House Foo()."); }

        static void _Main()
         {
            //当重载调用时，类型最明确的优先匹配
            House h = new House();
            Foo(h);//Calls Foo(House)

            //尽管a在运行是House类型
            Asset a = new House();
            Foo(a);//Calls Foo(Asset)

            //把Asset类转换为dynamic
            Foo((dynamic)a);    //Call Foo(House)        
        }
    }
}
